package com.learn.xueer.ui.activity


import android.os.Bundle

import androidx.recyclerview.widget.LinearLayoutManager
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.learn.xueer.app.base.BaseActivity1
import com.learn.xueer.app.ext.init
import com.learn.xueer.data.model.bean.HearSayQuestionResourceItem
import com.learn.xueer.databinding.ActivitySubmitHearSayBinding
import com.learn.xueer.ui.adapter.SubmitHearSayAdapter
import com.learn.xueer.ui.viewmodel.RequestHearViewModel
import kotlinx.android.synthetic.main.activity_submit_hear_say.recyclerView
import kotlinx.android.synthetic.main.activity_submit_hear_say.tvTitle

class SubmitHearSayActivity : BaseActivity1<RequestHearViewModel, ActivitySubmitHearSayBinding>() {

    private var id: String? = null
    private var title: String? = null
    private var resMain: String? = null
    private var items: ArrayList<HearSayQuestionResourceItem>? = null
    private var answerList: ArrayList<String>? = null
    private val submitHearSayAdapter: SubmitHearSayAdapter by lazy {
        SubmitHearSayAdapter(
            arrayListOf()
        )
    }

    override fun initView(savedInstanceState: Bundle?) {
        addLoadingObserve(mViewModel)
        id = intent.getStringExtra("id")
        title = intent.getStringExtra("title")
        resMain = intent.getStringExtra("resMain")
        val itemsStr = intent.getStringExtra("items")
        items = Gson().fromJson<ArrayList<HearSayQuestionResourceItem>>(itemsStr!!,
            object : TypeToken<ArrayList<HearSayQuestionResourceItem>>() {}.type
        )
        answerList = Gson().fromJson(intent.getStringExtra("answerList"),
            object : TypeToken<ArrayList<String>>() {}.type)
        submitHearSayAdapter.setResMain(resMain!!)
        submitHearSayAdapter.setAnswerList(answerList)
        recyclerView.init(LinearLayoutManager(this), submitHearSayAdapter)
        submitHearSayAdapter.setList(items)

        tvTitle.text = title
        mViewBind.click = ProxyClick()
    }

    override fun onPause() {
        super.onPause()
    }

    override fun onResume() {
        super.onResume()
    }

    override fun createObserver() {

    }

    inner class ProxyClick {
        fun returnBack() {
            finish()
        }
    }
}